package com.example.config.config;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;

import java.util.List;

/**
 * @desc: 请求路径配置
 * @author: liuhan
 * @create: 2023-12-30 23:02
 */
@Configuration
@AllArgsConstructor
public class WebSecurityConfig{
    private IgnoreSecurityProperties ignoreSecurityProperties;
    @Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        return (webSecurity) -> {
            WebSecurity.IgnoredRequestConfigurer irc = webSecurity.ignoring();
            List<String> igGetUrls = ignoreSecurityProperties.getGet();
            irc.requestMatchers(HttpMethod.GET, igGetUrls.toArray(new String[igGetUrls.size()]));

            List<String> igPostUrls = ignoreSecurityProperties.getPost();
            irc.requestMatchers(HttpMethod.POST, igPostUrls.toArray(new String[igGetUrls.size()]));

            List<String> igAllUrls = ignoreSecurityProperties.getAll();
            irc.requestMatchers(igAllUrls.toArray(new String[igGetUrls.size()]));
        };
    }
}
